<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理API文档</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6; color: #333; background: #f5f5f5; }
        .container { max-width: 1200px; margin: 0 auto; padding: 20px; }
        header { background: #2c3e50; color: white; padding: 2rem; text-align: center; margin-bottom: 2rem; border-radius: 8px; }
        h1 { font-size: 2.5rem; margin-bottom: 0.5rem; }
        .subtitle { font-size: 1.1rem; opacity: 0.9; }
        .card { background: white; border-radius: 8px; padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
        h2 { color: #2c3e50; margin-bottom: 1rem; border-bottom: 2px solid #3498db; padding-bottom: 0.5rem; }
        .endpoint { margin-bottom: 2rem; }
        .method { display: inline-block; padding: 0.3rem 0.8rem; border-radius: 4px; color: white; font-weight: bold; margin-right: 0.5rem; }
        .get { background: #3498db; }
        .post { background: #27ae60; }
        .put { background: #f39c12; }
        .delete { background: #e74c3c; }
        .url { font-family: monospace; background: #f8f9fa; padding: 0.5rem; border-radius: 4px; display: inline-block; }
        .code-block { background: #2c3e50; color: #ecf0f1; padding: 1rem; border-radius: 4px; margin: 1rem 0; overflow-x: auto; }
        pre { margin: 0; }
        .param-table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
        .param-table th, .param-table td { padding: 0.8rem; text-align: left; border-bottom: 1px solid #ddd; }
        .param-table th { background: #f8f9fa; font-weight: 600; }
        .example { background: #e8f4f8; border-left: 4px solid #3498db; padding: 1rem; margin: 1rem 0; border-radius: 4px; }
        .success { color: #27ae60; }
        .error { color: #e74c3c; }
        .copy-btn { background: #3498db; color: white; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; margin-top: 0.5rem; }
        .copy-btn:hover { background: #2980b9; }
        footer { text-align: center; margin-top: 3rem; padding: 2rem; color: #7f8c8d; }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>用户管理API文档</h1>
            <p class="subtitle">Spring Boot 3.2.0 · MySQL · RESTful API</p>
        </header>

        <div class="card">
            <h2>基础信息</h2>
            <p><strong>基础URL:</strong> <code>http://localhost:8080</code></p>
            <p><strong>内容类型:</strong> <code>application/json</code></p>
            <p><strong>数据库:</strong> MySQL</p>
            <p><strong>技术栈:</strong> Spring Boot 3.2.0, Hibernate 6.3.1, JPA</p>
        </div>

        <div class="card">
            <h2>API端点</h2>

            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/users</span>
                <p>获取所有用户列表</p>
                
                <div class="example">
                    <h4>示例请求:</h4>
                    <div class="code-block">
                        <pre>Invoke-RestMethod -Uri "http://localhost:8080/api/users" -Method Get</pre>
                    </div>
                </div>

                <div class="example">
                    <h4>响应示例:</h4>
                    <div class="code-block">
                        <pre>[
  {
    "id": 1,
    "username": "john_doe",
    "password": "hashed_password",
    "email": "john@example.com",
    "name": "John Doe",
    "createdAt": "2024-01-15T10:30:00",
    "updatedAt": "2024-01-15T10:30:00"
  }
]</pre>
                    </div>
                </div>
            </div>

            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/users/{id}</span>
                <p>根据ID获取特定用户</p>
                
                <table class="param-table">
                    <tr><th>参数</th><th>类型</th><th>描述</th></tr>
                    <tr><td>id</td><td>Long</td><td>用户ID</td></tr>
                </table>

                <div class="example">
                    <h4>示例请求:</h4>
                    <div class="code-block">
                        <pre>Invoke-RestMethod -Uri "http://localhost:8080/api/users/1" -Method Get</pre>
                    </div>
                </div>
            </div>

            <div class="endpoint">
                <span class="method post">POST</span>
                <span class="url">/api/users</span>
                <p>创建新用户</p>
                
                <table class="param-table">
                    <tr><th>字段</th><th>类型</th><th>必填</th><th>描述</th></tr>
                    <tr><td>username</td><td>String</td><td>是</td><td>用户名（唯一）</td></tr>
                    <tr><td>password</td><td>String</td><td>是</td><td>密码</td></tr>
                    <tr><td>email</td><td>String</td><td>是</td><td>邮箱（唯一）</td></tr>
                    <tr><td>name</td><td>String</td><td>否</td><td>真实姓名</td></tr>
                </table>

                <div class="example">
                    <h4>示例请求:</h4>
                    <div class="code-block">
                        <pre>$body = @{
    username = "testuser"
    password = "password123"
    email = "test@example.com"
    name = "Test User"
} | ConvertTo-Json

Invoke-RestMethod -Uri "http://localhost:8080/api/users" -Method Post `
    -Headers @{"Content-Type"="application/json"} -Body $body</pre>
                    </div>
                </div>
            </div>

            <div class="endpoint">
                <span class="method put">PUT</span>
                <span class="url">/api/users/{id}</span>
                <p>更新用户信息</p>
                
                <table class="param-table">
                    <tr><th>参数</th><th>类型</th><th>描述</th></tr>
                    <tr><td>id</td><td>Long</td><td>用户ID</td></tr>
                </table>
            </div>

            <div class="endpoint">
                <span class="method delete">DELETE</span>
                <span class="url">/api/users/{id}</span>
                <p>删除用户</p>
                
                <table class="param-table">
                    <tr><th>参数</th><th>类型</th><th>描述</th></tr>
                    <tr><td>id</td><td>Long</td><td>用户ID</td></tr>
                </table>
            </div>
        </div>

        <div class="card">
            <h2>错误处理</h2>
            <p><span class="error">400 Bad Request</span> - 请求参数错误</p>
            <p><span class="error">404 Not Found</span> - 用户不存在</p>
            <p><span class="error">409 Conflict</span> - 用户名或邮箱已存在</p>
            <p><span class="error">500 Internal Server Error</span> - 服务器内部错误</p>
        </div>

        <div class="card">
            <h2>快速开始</h2>
            <ol>
                <li>确保MySQL服务运行</li>
                <li>修改 <code>src/main/resources/application.properties</code> 中的数据库配置</li>
                <li>运行项目: <code>mvn spring-boot:run</code> 或双击 <code>run.bat</code></li>
                <li>访问 <code>http://localhost:8080</code> 测试API</li>
            </ol>
        </div>

        <footer>
            <p>© 2024 用户管理系统 | 基于 Spring Boot 3.2.0</p>
        </footer>
    </div>

    <script>
        // 复制代码功能
        document.querySelectorAll('.code-block').forEach(block => {
            const button = document.createElement('button');
            button.className = 'copy-btn';
            button.textContent = '复制代码';
            button.onclick = () => {
                const code = block.querySelector('pre').textContent;
                navigator.clipboard.writeText(code).then(() => {
                    button.textContent = '已复制!';
                    setTimeout(() => button.textContent = '复制代码', 2000);
                });
            };
            block.appendChild(button);
        });
    </script>
</body>
</html>